package com.zmj.sy.mom.srv.aps.controller;


import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseIdReqVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseListResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.position.*;
import com.zmj.sy.mom.srv.aps.config.AspectLog;
import com.zmj.sy.mom.srv.aps.service.PositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RequiredArgsConstructor
@Api(tags = "料位")
@RestController
@RequestMapping("/position")
public class PositionController {

    private final PositionService positionService;

    @ApiOperation("添加料位")
    @PostMapping("/add")
    public BaseResVo add(@RequestBody PositionAddReqVo reqVo){
        positionService.add(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("同步料位")
    @PostMapping("/sysPosition")
    public BaseResVo sysPosition(@RequestBody PositionAddReqVo reqVo) throws IOException {
        positionService.sysPosition(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("料位列表")
    @GetMapping("/list")
    public BaseListResVo<PositionListResVo> list(BaseIdReqVo reqVo){
        return positionService.list(reqVo);
    }

    @ApiOperation("修改料位")
    @PostMapping("/edit")
    public BaseResVo edit(@RequestBody PositionEditReqVo reqVo){
        positionService.edit(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("删除料位")
    @PostMapping("/delete")
    public BaseResVo delete(BaseIdReqVo reqVo){
        positionService.delete(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("托盘到达")
    @PostMapping("/trayIn")
    @AspectLog(apiName = "托盘进入", operationType = 4)
    public BaseResVo trayIn(PositionTrayInReqVo reqVo) {
        positionService.trayIn(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("托盘离开")
    @PostMapping("/trayOut")
    @AspectLog(apiName = "托盘离开", operationType = 4)
    public BaseResVo trayOut(PositionTrayOutReqVo reqVo) {
        positionService.trayOut(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("零件到达位置")
    @PostMapping("/partIn")
    @AspectLog(apiName = "零件到达位置", operationType = 4)
    public BaseResVo partIn(PositionPartInReqVo reqVo) {
        if(reqVo.getPartType() == null){
            reqVo.setPartType(2);
        }
        positionService.partIn(reqVo);
        return BaseResVo.ok();
    }
    @ApiOperation("组件到达")
    @PostMapping("/assembleIn")
    @AspectLog(apiName = "组件到达", operationType = 4)
    public BaseResVo assembleIn(AssembleInReqVo reqVo) {
        positionService.assembleIn(reqVo);
        return BaseResVo.ok();
    }
    @ApiOperation("组件离开")
    @PostMapping("/assembleLeave")
    @AspectLog(apiName = "组件离开", operationType = 4)
    public BaseResVo assembleLeave(AssembleInReqVo reqVo) {
        positionService.assembleLeave(reqVo);
        return BaseResVo.ok();
    }
    @ApiOperation("零件脱离位置")
    @PostMapping("/partOut")
    @AspectLog(apiName = "零件脱离位置", operationType = 4)
    public BaseResVo partOut(PositionPartOutReqVo reqVo) {
        if(reqVo.getPartType() == null){
            reqVo.setPartType(2);
        }
        positionService.partOut(reqVo);
        return BaseResVo.ok();
    }


}
